package com.xique.park.controller.auto;

import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.page.TableDataInfo;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.bean.domain.ParkPayPp;
import com.xique.park.service.service.IParkPayPpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 第三方支付停车场配置信息（p云）Controller
 * 
 * @author xique
 * @date 2021-12-09
 */
@RestController
@RequestMapping("/payPp")
public class ParkPayPpController extends BaseController
{
    @Autowired
    private IParkPayPpService parkPayPpService;

    /**
     * 查询第三方支付停车场配置信息（p云）列表
     */
    @PreAuthorize(hasPermi = "park:pp:list")
    @GetMapping("/list")
    public TableDataInfo list(ParkPayPp parkPayPp)
    {
        startPage();
        List<ParkPayPp> list = parkPayPpService.selectParkPayPpList(parkPayPp);
        return getDataTable(list);
    }

    /**
     * 导出第三方支付停车场配置信息（p云）列表
     */
    @PreAuthorize(hasPermi = "park:pp:export")
    @Log(title = "第三方支付停车场配置信息（p云）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkPayPp parkPayPp) throws IOException
    {
        List<ParkPayPp> list = parkPayPpService.selectParkPayPpList(parkPayPp);
        ExcelUtil<ParkPayPp> util = new ExcelUtil<ParkPayPp>(ParkPayPp.class);
        util.exportExcel(response, list, "第三方支付停车场配置信息（p云）数据");
    }

    /**
     * 获取第三方支付停车场配置信息（p云）详细信息
     */
    @PreAuthorize(hasPermi = "park:pp:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(parkPayPpService.selectParkPayPpById(id));
    }

    /**
     * 新增第三方支付停车场配置信息（p云）
     */
    @PreAuthorize(hasPermi = "park:pp:add")
    @Log(title = "第三方支付停车场配置信息（p云）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkPayPp parkPayPp)
    {
        return toAjax(parkPayPpService.insertParkPayPp(parkPayPp));
    }

    /**
     * 修改第三方支付停车场配置信息（p云）
     */
    @PreAuthorize(hasPermi = "park:pp:edit")
    @Log(title = "第三方支付停车场配置信息（p云）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkPayPp parkPayPp)
    {
        return toAjax(parkPayPpService.updateParkPayPp(parkPayPp));
    }

    /**
     * 删除第三方支付停车场配置信息（p云）
     */
    @PreAuthorize(hasPermi = "park:pp:remove")
    @Log(title = "第三方支付停车场配置信息（p云）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(parkPayPpService.deleteParkPayPpByIds(ids));
    }

    /**
     * 删除第三方支付停车场配置信息（p云）
     */
    @PreAuthorize(hasPermi = "park:pp:remove")
    @Log(title = "第三方支付停车场配置信息（p云）", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult delete(@RequestParam("parkId") Long parkId)
    {
        ParkPayPp request = new ParkPayPp();
        request.setParkId(parkId);
        List<ParkPayPp> parkPayPps = parkPayPpService.selectParkPayPpList(request);
        if (!parkPayPps.isEmpty()){
            return toAjax(parkPayPpService.deleteParkPayPpById(parkPayPps.get(0).getId()));
        }
       return AjaxResult.success("车场未配置支付参数，无需删除！");
    }

    @GetMapping("/getParkPayPp")
    public AjaxResult getParkPayPp(Long parkId)
    {
        ParkPayPp parkPayPp = new ParkPayPp();
        parkPayPp.setParkId(parkId);
        List<ParkPayPp> list = parkPayPpService.selectParkPayPpList(parkPayPp);
        return AjaxResult.success(list);
    }
}
